// http.js 里面
// 现在引入我们的 request.js
import request from "./request.js"

// // 接口
//  let getData = function(e){
//  	 return request.getRequest("/index/api.index/list",e)
//  },

// 缓存接口
let myCache = function(key, value, seconds) {
	let nowTime = Date.parse(new Date()) / 1000;
	if (key && value) {
		let expire = nowTime + Number(seconds);
		uni.setStorageSync(key,JSON.stringify(value) + '|' +expire)
		console.log('已经把' + key + '存入缓存,过期时间为' + expire)
	} else if (key && !value) {
		let val = uni.getStorageSync(key);
		if (val) {
			// 缓存存在，判断是否过期
			let temp = val.split('|')
			if (!temp[1] || temp[1] <= nowTime) {
				uni.removeStorageSync(key)
				console.log(key + '缓存已失效')
				return '';
			} else {
				return JSON.parse(temp[0]);
			}
		}
	}

}




//轮播  index/getSlider
let getlogins = function(e) {
	return request.getRequest("index/getSlider", e)
}

//首页 菜单 index/getMenu
let getMenu = function(e) {
	return request.getRequest("index/getMenu", e)
}
//首页 广告 index/getNotify
let getNotify = function(e) {
	return request.getRequest("index/getNotify", e)
}

//首页 分类 index/getCate
let getCate = function(e) {
	return request.getRequest("index/getCate", e)
}


//首页 现时秒杀 //index/getGoods
let getGoods = function(e) {
	return request.getRequest("index/getGoods", e)
}


//首页 全部商品 //index/getAllGoods
let getAllGoods = function(e) {
	return request.getRequest("index/getAllGoods", e)
}
//index/getAllCateGoods 分类
let getAllCateGoods = function(e) {
	return request.getRequest("index/getAllCateGoods", e)
}


//发送验证码 sms/send
let postsend = function(e) {
	return request.postRequest("/api/sms/send", e)
}

//  index/getItem
let getgetItem = function(e) {
	return request.getRequest("index/getItem", e)
}


//登录 login/login
let postlogin = function(e) {
	return request.postRequest("login/login11", e)
}


// 添加购物车 order/addCart
let postaddCart = function(e) {
	return request.postRequest("order/addCart", e)
}

//  order/getCart
let getgetCart = function(e) {
	return request.getRequest("order/getCart", e)
}

// order/jiaCart 购物车 +
let postjiaCart = function(e) {
	return request.postRequest("order/jiaCart", e)
}
// order/jianCart 购物车 -
let postjianCart = function(e) {
	return request.postRequest("order/jianCart", e)
}
// order/delCart 删除购物车信息
let postdelCart = function(e) {
	return request.postRequest("order/delCart", e)
}

//address/set 添加地址
let postaddress = function(e) {
	return request.postRequest("address/set", e)
}
//  查询订单信息 order/getyorder
let getgetyorder = function(e) {
	return request.getRequest("order/getyorder", e)
}

// 获取地址address/get
let getaddress = function(e) {
	return request.getRequest("address/get", e)
}

// 下单order/addorder
let postaddorder = function(e) {
	return request.postRequest("order/addorder", e)
}

// order/getorder 订单列表
let getgetorder = function(e) {
	return request.getRequest("order/getorder", e)
}


// 扫货 ewmlog/set
let postewmlog = function(e) {
	return request.postRequest("ewmlog/set", e)
}

// 最下面记得抛出
export default {
	getlogins,
	postsend,
	getMenu,
	getNotify,
	getCate,
	getGoods,
	getAllGoods,
	getAllCateGoods,
	getgetItem,
	postlogin,
	myCache,
	postaddCart,
	getgetCart,
	postjiaCart,
	postjianCart,
	postdelCart,
	getgetyorder,
	postaddress,
	getaddress,
	postaddorder,
	getgetorder,
	postewmlog
}
